// 异步等待
// 延迟执行
setTimeout(() => {
    console.log(" world")
}, 0)
setTimeout((firstname, lastname) => {
    this.firstname = firstname;
    this.lastname = lastname;
    return firstname + lastname;
}, 5000);




let i = 0
    //循环执行
let a = setInterval(() => {
    console.log("□", i)
    i++;
    if (i > 10) {
        clearInterval(a)
    }
}, 500)


// var nll = null
var un = undefined;
var b = false;
var str = "str"

function a() {}
var age = 3;
let arr = [1, 2, 3, 4, 5, 6]
let type = typeof(un)

console.log(type)

let arrobj = [
    { name: 'robin', id: 1 },
    { name: "dvid", id: 2 }
]

//数组里面是对象时 ，查找用find
arrobj.find(i => i.name === "make")

//数组里面是基本数据类型 用indexOf
let index = arr.indexOf(4) //3 -1

//翻转数组
let res = arr.reverse();
console.log(res)
console.log(arr)
    // 最后添加
arr.push(7)
    // 删除最后一个元素
arr.pop()

// 前边删除
arr.shift()
    // 前边添加
arr.unshift(0)


// 指定位置删几个
arr.splice(2, 0, 0)


console.log(arr)


for (var i = 0; i < arr.length; i++) {
    console.log(arr[i])
}


arr.forEach(function(i) {
    console.log(i)
})


for (var i = 0; i < arr.length; i++) {
    var temp = ""
    console.log(arr[i] + 2)
    var age = arr[i]
}

console.log("age", age)
console.log("I", i)

arr.forEach(function(i, index, arr) {
    console.log("i", i)
    console.log("index", index)
    console.log('arr', arr)
})


let b3 = []
arr.forEach(i => {
    if (i > 2) {
        b3.push(i)
    }
})

console.log(b3)

//必须每个都满足才返回true
let isAllBigThan3 = arr.every(i => i > 0)

//有一个满足就返回true
arr.some(i => i > 4)

// 生成一个新数组
let newArr = arr.map(i => { return "<div>" + i + "</div>" })
console.log(newArr)
    // i => { return i > 3 }
    // i => i > 3;

function a(i) { return i > 3 }



let b2 = arr.find(i => {
    return i > 2
})



function cb(i) {
    console.log(i + 2)
}

function forEach(callback) {
    for (var i = 0; i < arr.length; i++) {
        callback(arr)
    }
}

forEach(cb)